package com.hl.card.pay.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;


@Configuration
public class RestTemplateConfig {

    private RestTemplate httpRestTemplate;
    private RestTemplate httpsRestTemplate;
    @Bean
    public RestTemplate restTemplate(@Qualifier("restFactory") ClientHttpRequestFactory factory){
        return new RestTemplate(factory);
    }
    @Bean(name = "restFactory")
    public ClientHttpRequestFactory simpleClientHttpRequestFactory(){
        SimpleClientHttpRequestFactory factory=new SimpleClientHttpRequestFactory();
        factory.setConnectTimeout(15000);
        factory.setReadTimeout(5000);
        return factory;
    }

    public void init() {
        this.httpsRestTemplate = new RestTemplate(new HttpsClientRequestFactory());
        this.httpRestTemplate = new RestTemplate();
    }


}
